<template>
  <div class="home bg-fff">
    <!-- 轮播图 -->
    <Swiper></Swiper>
    <!-- <van-swipe class="my-swipe" :autoplay="3000" indicator-color="blue">
      <van-swipe-item v-for="img in imgList" :key="img">
        <img :src="img" alt="" class="w100p" />
      </van-swipe-item>
    </van-swipe> -->

    <!-- 分类列表 -->
    <dl class="type-list bg-fff w100p pt-10">
      <li class="item flex aic jc-sa fww">
        <dd v-for="item in typeList" :key="item.categoryId" class="flex main fcc fdc mt-20" style="width: 25%;">
          <router-link :to="{ name: 'Type', params: { categoryId: item.categoryId } }" class="flex fcc fdc">
            <img :src="item.iconUrl">
            <span class="pt-10">{{ item.name }}</span>
        </router-link>
        </dd>
      </li>
    </dl>
    <div class="miaopin">
      <div class="miaosha l">
        <span class="rs">秒杀</span>
        <div class="kanjia">
          <p class="f14">秒杀</p>
          <p class="grey f10">超值惊喜</p>
          <p class="redb f12">立即砍价</p>
        </div>
        <img src="http://fresh.huruqing.cn/img/miaosha-icon.e7d1fb11.png" alt="">
      </div>
      <div class="miaosha r">
        <span class="rs">拼团</span>
        <div class="kanjia">
          <p class="f14">拼团</p>
          <p class="grey f10">限时拼团</p>
          <p class="redb f12">一键拼团</p>
        </div>
        <img src="http://fresh.huruqing.cn/img/miaosha-icon.e7d1fb11.png" alt="">
      </div>
    </div>
    <div class="manjian">
      <div class="mj f14 flex jc-sb aic">
        <p class="flex aic">
          <van-icon size="18" name="coupon-o" />
          <span>超值福利</span>
          <span>|</span>
          <span>全场满减</span>
        </p>
        <p class="flex aic">
          <span>立即领取</span>
          <van-icon name="arrow" />
        </p>
      </div>
    </div>
    <!-- tabs -->
    <dt class="navbar flex aic jc-sa bg-fff">
      <span class="f14">推荐</span>
      <span class="f14">销量</span>
      <span class="f14">价格</span>
    </dt>
    <!-- 商品列表 -->
    <ul class="goods-list w100p flex fww">
      <li v-for="item in goodsList" :key="item.productId" class="list-item pt-10 f14">
        <!-- 动态绑定 to 属性，传递 productId -->
        <router-link :to="{ name: 'ProductDetail', params: { id: item.productId } }">
          <!--<dd class="con flex fdc ">-->
          <img :src="item.imgUrl">
          <h4 class="mt-10">{{ item.masterName }}</h4>
          <p class="mt-10">{{ item.slaveName }}</p>
          <p class="money flex jc-sb mt-10 mr-10">
            <span class="red">{{ (item.minPrice / 100).toFixed(2) }}</span>
            <span style="color: gray">销量：{{ item.inventory }}</span>
          </p>
        </router-link>
      </li>
    </ul>
    <div class="text  f14">没有更多了</div>
    <Footer />
  </div>
</template>

<script>
import request from "../../../utils/request";
import Footer from'../../components/Footer.vue';
import Swiper from "./Swiper.vue";
export default {
  components: {
    Swiper,
    Footer
  },
  //data是个方法，而且必须return一个对象
  data() {
    return {
      typeList: [], //分类列表数据
      goodsList: [],//商品列表数据
      imgList: [
        "https://mall.s.maizuo.com/03a19a63d2a4d5eeb5e96b4485c89370.jpg?x-oss-process=image/format,webp",
        "https://mall.s.maizuo.com/04d5b66b902d9261e70f6e7830f26ab9.png?x-oss-process=image/format,webp",
        "https://mall.s.maizuo.com/ae13cdf54f9552bbe0613d3cbb44b350.png?x-oss-process=image/format,webp"
      ],
      
    };
  },

  created() {
    this.getTypeList();
    this.getGoodsList();
  },

  methods: {
    //获取分类数据
    async getTypeList() {
      let res = await request.get("/category/all");
      this.typeList = res.list;
    },
    async getGoodsList() {
      let res = await request.get("/product/list");
      this.goodsList = res.list;
    },
  },
};
</script>

<style lang="less" scoped>
.home {
  body {
    background: #fff;
  }

  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 10px;
    text-align: center;
  }

  .type-list {
    img {
      width: 55px;
      height: 55px;
    }
  }

  .image {
    padding: 10px;

    img {
      width: 49%;
      height: auto;
    }
  }

  .manjian {
    padding: 10px;
    width: 100%;
  }

  .manjian .mj {
    height: 37px;
    background: url() 50% no-repeat;
    background-size: 100% 100%;
    color: #fff;

    p {
      margin-left: 5px;
      margin-right: 5px;

      span {
        margin-left: 5px;
      }
    }
  }

  .navbar {
    height: 48px;
    border-bottom: 1px solid #ededed;
  }

  .goods-list {
    width: 100%;
    padding-top: 15px;
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 20px;

    .list-item {
      width: 40%;
      margin-bottom: 10px;
      display: flex;
      flex-grow: 1;
      flex-direction: column;
      justify-content: space-between;
      color: #C8C9CC;

      img {
        width: 100%;
        height: 175px;
        background: #f4f4f4;
      }
    }

    .list-item:nth-child(even) {
      margin-left: 10px;
    }

    img {
      width: 406px;
      height: 411px;
      background-color: #f4f4f4;
    }
  }

  .text {
    text-align: center;
    padding-bottom: 10px;
    margin-bottom: 50px;
  }

  .miaopin {
    display: flex;
    padding: 10px;
  }

  .miaopin .miaosha {
    width: 50%;
    background-size: 100% 100%;
    min-height: 100px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-around;
    border-radius: 5px;
  }

  .miaopin .miaosha .rs {
    font-size: 10px;
    right: 1px;
    top: 6px;
    color: #fff;
    position: absolute;
  }

  .miaopin .miaosha img {
    width: 70px;
  }

  .grey {
    color: rgb(153, 153, 153);
    font-size: 10px;
    margin-top: 5px;
  }

  .redb {
    background: #d92c01;
    padding: 5px;
    border-radius: 3px;
    color: #fff;
    margin-top: 5px;
  }

  .l {
    background: url(http://fresh.huruqing.cn/img/miaosha-bg.1e1a2d1e.png) no-repeat 50%;
  }

  .r {
    background: url(http://fresh.huruqing.cn/img/pintuan-bg.e9cbdf93.png) no-repeat 50%;
    margin-left: 10px;
  }
}
</style>